import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
Item {
    id: root
    width: 130
    height: 130
    property int no:-1
    property int rowHeight:18
    function getText(){
        switch(no){
            case 0:
                return mymodbus.voltage0;
            case 1:
                return mymodbus.voltage1;
            case 2:
                return mymodbus.voltage2;
            case 3:
                return mymodbus.voltage3;
            case 4:
                return mymodbus.voltage4;
            case 5:
                return mymodbus.voltage5;
            case 6:
                return mymodbus.voltage6;
            case 7:
                return mymodbus.voltage7;
        }
    }
    Component.onCompleted: {
        //weigherValue.text = getText()
    }
    Component.onDestruction: {
        deviceTimer.running=false
        deviceTimer.destroy()
    }
    Rectangle{
        id:rec
        anchors.fill:parent
        color:"#7142ED"
        Text {
            id: weigherName
            text:qsTr("轴")+(no+1).toString()
            font.pixelSize: 15
            font.weight: Font.Medium
            color: "white"
            height: 20
            anchors.topMargin: 0
            anchors.top: parent.top

        }

        GridLayout{
                        id: normalSettingsLayout
                        rows: 6
                        columns: 2
                        anchors.centerIn: parent
                        anchors.topMargin: 20
                        anchors.verticalCenterOffset: 11
                        anchors.horizontalCenterOffset: 0
                        rowSpacing: 10
                        columnSpacing: 0
                        Text {
                            id: stable
                            text: {
                                if(mymodbus.stable===1){
                                    return qsTr("稳定")
                                }
                                else{
                                    return qsTr("不稳")
                                }
                            }
                                //qsTr("稳定")
                            color: "white"
                            font.pixelSize: 15

                            Layout.preferredWidth: root.width/2
                            Layout.preferredHeight: rowHeight
                            Layout.row:0
                            Layout.column:0
                        }
                        Text {
                            id: normal
                            text: {
                                if(mymodbus.normal===0){
                                    return qsTr("正常")
                                }
                                else{
                                    return qsTr("溢出")
                                }
                            }
                                //qsTr("正常")
                            color: "white"
                            font.pixelSize: 15

                            Layout.row:0
                            Layout.column:1
                            Layout.preferredWidth: root.width/2
                            Layout.preferredHeight: rowHeight
                        }
                        Text {
                            id: nonZero
                            text: {
                                if(mymodbus.zero===0){
                                    return qsTr("非零")
                                }
                                else{
                                    return qsTr("零点")
                                }
                            }
                                //qsTr("非零")
                            color: "white"
                            font.pixelSize: 15

                            Layout.row:1
                            Layout.column:0
                            Layout.preferredWidth: root.width/2
                            Layout.preferredHeight: rowHeight
                        }
                        Text {
                            id: positive
                            text: {
                                if(mymodbus.positive===0){
                                    return qsTr("正号")
                                }
                                else{
                                    return qsTr("负号")
                                }
                            }
                                //qsTr("正号")
                            color: "white"
                            font.pixelSize: 15

                            Layout.row:1
                            Layout.column:1
                            Layout.preferredWidth: root.width/2
                            Layout.preferredHeight: rowHeight
                        }
                        Text{
                                            id:weight
                                            Layout.row:2
                                            Layout.column:0
                                            Layout.columnSpan: 2
                                            Layout.preferredWidth: root.width
                                            Layout.preferredHeight: rowHeight
                                            text:qsTr("重量:")
                                            //echoMode: TextInput.Password
                                            color:"white"
                                            font.pixelSize: 15
                                            horizontalAlignment: Text.AlignLeft
                                            verticalAlignment: Text.AlignVCenter

                                        }
                        Text{
                                            id:voltage
                                            Layout.row:3
                                            Layout.column:0
                                            Layout.columnSpan: 2
                                            Layout.preferredWidth: root.width
                                            Layout.preferredHeight: rowHeight
                                            text:qsTr("电压:")
                                            //echoMode: TextInput.Password
                                            color:"white"
                                            font.pixelSize: 15
                                            horizontalAlignment: Text.AlignLeft
                                            verticalAlignment: Text.AlignVCenter


                                        }
        }

    }
    Timer{
        id:deviceTimer
        interval: mymodbus.collectTime
        running: true
        repeat: true
        onTriggered: {
            weight.text = qsTr("重量:")+getText()+mymodbus.unit
            //mymodbus.getCollectData0(no)
            stable.text=mymodbus.getStable(no)===1?qsTr("稳定"):qsTr("不稳")
            normal.text=mymodbus.getNormal(no)===0?qsTr("正常"):qsTr("溢出")
            nonZero.text=mymodbus.getZero(no)===0?qsTr("非零"):qsTr("零点")
            positive.text=mymodbus.getPositive(no)===0?qsTr("正号"):qsTr("负号")
            //mymodbus.getCollectVoltage(no)
            //voltage
            voltage.text = qsTr("电压:")+mymodbus.getVoltageById(no)+"uV"
            //voltage.text = qsTr("电压:")+mymodbus.voltage(no)+"uV"
        }

    }
}
